import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemCustomerApi {
  export interface SystemCustomer {
    [key: string]: any;
    /** 记账会计 */
    accountant: string;
    /** 制单会计 */
    bookkeeper: string;
    /** 创建时间 */
    createTime?: string;
    /** 客户编号 */
    customerCode: string;
    /** 客户名称 */
    customerName: string;
    id: string;
    /** 组织名称 */
    organizationName: string;
    /** 备注 */
    remark?: string;
    /** 状态 */
    status: 0 | 1;
    /** 主管会计 */
    supervisor: string;
  }
}

/**
 * 获取客户列表数据
 */
async function getCustomerList(params?: Recordable<any>) {
  const response = await requestClient.get<{
    list: Array<SystemCustomerApi.SystemCustomer>;
    total: number;
  }>('/system/customer/list', { params });
  return response.list || [];
}

/**
 * 创建客户
 * @param data 客户数据
 */
async function createCustomer(
  data: Omit<SystemCustomerApi.SystemCustomer, 'id'>,
) {
  return requestClient.post('/system/customer', data);
}

/**
 * 更新客户
 * @param id 客户 ID
 * @param data 客户数据
 */
async function updateCustomer(
  id: string,
  data: Omit<SystemCustomerApi.SystemCustomer, 'id'>,
) {
  return requestClient.put(`/system/customer/${id}`, data);
}

/**
 * 删除客户
 * @param id 客户 ID
 */
async function deleteCustomer(id: string) {
  return requestClient.delete(`/system/customer/${id}`);
}

export { createCustomer, deleteCustomer, getCustomerList, updateCustomer };